﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit Asset
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CurrentMenuIDContent" runat="server" >assetMenu</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <link rel="stylesheet" type="text/css" href="../../Content/jquery-ui-1.8.16.custom.css" />
    <script type="text/javascript" src="../../Scripts/site.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.pager.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Edit Asset</h2><br />
    <fieldset>
        <% Using Html.BeginForm()%>
        <legend></legend>
        <div id="formContainer">
        <table width="100%">
            <tr>
                <td width="130px">
                    <label for="Id">
                        Asset ID:</label>
                </td>
                <td>
                    <%= Html.Encode(ViewData("AssetID"))%>
                     <%= Html.Hidden("hfStatusID", ViewData("StatusID"))%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Id">
                        AssetName:</label>
                        <% If ViewData("AssetNameRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.TextBox("AssetName", ViewData("AssetName"), New With {.class = "text normal-width"})%>
                    <%= Html.ValidationMessage("AssetName")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Id">
                        Asset Type:</label>
                        <% If ViewData("AssetTypeRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.DropDownList("AssetType")%>
                    <%= Html.ValidationMessage("AssetType")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Id">
                        Asset Barcode ID:</label>
                        <% If ViewData("AssetBarcodeRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.TextBox("BarcodeID", ViewData("BarcodeID"), New With {.class = "text normal-width"})%>
                    <%= Html.ValidationMessage("BarcodeID")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Id">
                        Model #:</label>
                        <% If ViewData("ModelNoRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.TextBox("ModelNo", ViewData("ModelNo"), New With {.class = "text normal-width"})%>
                    <%= Html.ValidationMessage("ModelNo")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Id">
                        Serial #:</label>
                        <% If ViewData("SerialNoRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.TextBox("SerialNo", ViewData("SerialNo"), New With {.class = "text normal-width"})%>
                    <%= Html.ValidationMessage("SerialNo")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Site">
                        Site:</label>
                </td>
                <td>
                    <%= Html.DropDownList("Site")%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Department">
                        Department:</label>
                        <% If ViewData("DepartmentRequired") IsNot Nothing Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <div id="departmentContainer">
                        <%= Html.DropDownList("Department")%>
                        <%= Html.ValidationMessage("Department")%>
                    </div>
                </td>
            </tr>
            <% For Each item In ViewData("CustomTextFields")%>
            <tr>
                <td>
                    <label for="<%:String.Concat("textField_", item.ID) %>">
                        <%= Html.Encode(item.FieldName)%>:</label>
                        <% If item.Mandatory Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.TextBox(String.Concat("textField_", item.ID), ViewData(String.Concat("textField_", item.ID)), New With {.class = "text normal-width"})%>
                    <%= Html.ValidationMessage(String.Concat("textField_", item.ID))%>
                </td>
            </tr>
            <% Next%>
            <% For Each item In ViewData("CustomDDFields")%>
            <tr>
                <td>
                      <label for="<%:String.Concat("ddField_", item.ID) %>">
                        <%= Html.Encode(item.FieldName)%>:</label>
                        <% If item.Mandatory Then%>
                            <span class="required-mark">*</span>
                        <%End If%>
                </td>
                <td>
                    <%= Html.DropDownList("ddField_" & item.ID, New SelectList(item.Values.Split(";"), ViewData(String.Concat("ddField_", item.ID))))%>
                    <%= Html.ValidationMessage(String.Concat("ddField_", item.ID))%>
                </td>
            </tr>
            <% Next%>
        </table>
        </div>
        <div class="left">
            <input type="submit" class="button" value="Save" />
        </div>
        <% End Using%>
        <%  Html.RenderPartial("~/Views/Asset/Controls/StatusDialog.ascx")%>
        <div class="left">
            <form method="get" action='<%= Html.AttributeEncode(Url.Action("LinkRequirements")) %>/<%= Html.Encode(ViewData("AssetID"))%>'>
            &nbsp;&nbsp;&nbsp;<input type="submit" class="button" value="Link Requirements" />
            </form>
        </div>
        <div class="left">
            &nbsp;&nbsp;&nbsp;<input type="submit" class="button" value="Change Status" onclick='statusDialog.show(<%= Html.Encode(ViewData("AssetID"))%>);'/>
        </div>
    </fieldset>
    <% Html.RenderPartial("~/Views/History/Controls/EntityHistory.ascx")%>
    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>
    <script type="text/javascript">
                statusDialog.OnSuccess = function (id) {
                    $("#hfStatusID").val(id);
                }

                $(document).ready(function () {
                    $("#Site").change(function () {
                        getDepartmentsBySite();
                    });

                });


                function getDepartmentsBySite() {
                    showLoading("formContainer", true);
                    var siteId = $("#Site").val();
                    if (siteId === "") {
                        return;
                    }
                    jQuery.ajax({
                        type: 'POST',
                        data: { id: siteId },
                        url: '<%= Html.AttributeEncode(Url.Action("GetDepartmentsBySite")) %>',
                        success: function (result) {
                            $('#departmentContainer').html(result);
                            hideLoading("formContainer");
                        }
                    });
                }

    </script>
</asp:Content>
